import Router from '@koa/router';
import logger from '../logger.js';
import busniess from '../business.js';
import response from '../response.js';



const router = new Router;
router.prefix('/api');

router.post('/busniess/addParkInfo', async (ctx) => {
    let body = ctx.request.body;
    if (!body.park_no || !body.lot) {
        ctx.body = response.fail('请求参数错误');
        return;
    }
    let park_no = body.park_no;
    let lot = body.lot;
    await busniess.addParkInfo(park_no, lot, body.available_lot);
    ctx.body = response.success();
});
//删除车场信息
router.post('/busniess/removeParkInfo', async (ctx) => {
    let body = ctx.request.body;
    if (!body.park_no) {
        ctx.body = response.fail('请求参数错误');
        return;
    }
    let park_no = body.park_no;
    await busniess.removeParkInfo(park_no);
    ctx.body = response.success();
});
//添加通道信息
router.post('/busniess/addChannelInfo', async (ctx) => {
    let body = ctx.request.body;
    if (!body.park_no || !body.camera_sn || body.is_entrance == undefined) {
        ctx.body = response.fail('请求参数错误');
        return;
    }
    let park_no = body.park_no;
    let camera_sn = body.camera_sn;
    let is_entrance = body.is_entrance;
    await busniess.addChannelInfo(park_no, camera_sn, is_entrance);
    ctx.body = response.success();
});
//删除通道信息
router.post('/busniess/removeChannelInfo', async (ctx) => {
    let body = ctx.request.body;
    let camera_sn = body.camera_sn;
    if (!camera_sn) {
        ctx.body = response.fail('请求参数错误');
        return;
    }
    await busniess.removeChannelInfo(camera_sn);
    ctx.body = response.success();
});
//获取车场信息列表
router.get('/busniess/getParkInfo', async (ctx) => {
    ctx.body = response.success(busniess.getParkInfo());
});
//获取通道信息列表
router.get('/busniess/getChannelInfo', async (ctx) => {
    ctx.body = response.success(busniess.getChannelInfo());
});




export { router };